package com.itheima.service.impl;

import com.itheima.mapper.DeptLogMapper;
import com.itheima.pojo.DeptLog;
import com.itheima.service.DeptLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class DeptLogServiceImpl implements DeptLogService {

    @Autowired
    private DeptLogMapper deptLogMapper;


    /**
     * @Transactional注解当中的第二个属性propagation，这个属性是用来配置事务的传播行为的。
     * REQUIRED:【默认值】需要事务，有则加入，无则创建新事务
     *REQUIRES_NEW:需要新事务，无论有无，总是创建新事务
     *
     * 1.运行时，创建新的事物Creating new transaction with name [com.itheima.service.impl.DeptServiceImpl.delete]
     * 2.Suspending current transaction, creating new transaction with name [com.itheima.service.impl.DeptLogServiceImpl.insert]。
     *  运行insert方法时，会挂起当前事务，再创建并运行一个事务
     *  3.Initiating transaction commit。事务提交
     *  4.Resuming suspended transaction after completion of inner transaction
     *      当内部事务完成之后，再继续运行刚才挂起的事务，会被正常的回滚：Initiating transaction rollback
     * @param deptLog
     */
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void insert(DeptLog deptLog) {
        deptLogMapper.insert(deptLog);
    }
}
